<?php

namespace app\common\model;
/**
 * 申请试用
 * User: Feng
 * Date: 2024/05/30
 * @package app\common\model
 */
class Apply extends Common
{
	public function tableData($post)
	{
		if (isset($post['limit'])) {
			$limit = $post['limit'];
		} else {
			$limit = config('paginate.list_rows');
		}
		$tableWhere = $this->tableWhere($post);
		$list = $this->field('*')->where($tableWhere['where'])->order($tableWhere['order'])->paginate($limit);
		foreach ($list as $key => $val) {
			$list[$key]['ctime'] = getTime($val['ctime']);
			//试用状态 0未试用 1已试用
			if($val['status'] == 1){
				$list[$key]['status'] = '已试用';
			}else{
				$list[$key]['status'] = '未试用';
			}
		}
		$data = $this->tableFormat($list->getCollection());         //返回的数据格式化，并渲染成table所需要的最终的显示数据类型
		$re['code'] = 0;
		$re['msg'] = '';
		$re['count'] = $list->total();
		$re['data'] = $data;
		return $re;
	}

	protected function tableWhere($post)
	{
		$where = [];
		if (isset($post['title']) && $post['title'] != "") {
			$where[] = [
				'title',
				'like',
				'%' . $post['title'] . '%'
			];
		}
		$result['where'] = $where;
		$result['field'] = "*";
		$result['order'] = ['id' => 'ASC'];
		return $result;
	}
}